
package cn.yunyichina.provider.clinic.user;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;

import cn.yunyichina.provider.clinic.constant.BizConstant;
import cn.yunyichina.provider.clinic.utils.MedicalCardUtil;


public class EasyHealthUser extends MsgPushEntity implements Serializable{

	
	private static final long serialVersionUID = 9151554851072776653L;

	
	protected String hashTableName;

	
	private String account;

	
	private String name;

	
	private String mobile;

	
	private Integer cardType;

	
	private String cardNo;

	
	private String passWord;

	
	private String loginNonce;

	
	private String deviceNumber;

	
	private Long registerTime;

	
	private Long lastLoginTime;

	
	private String birthDay;

	
	private Integer sex;

	
	private String address;

	
	private String alipayId;

	
	private String wecahtId;

	
	private String encryptedName;

	
	private String encryptedMobile;

	
	private String encryptedCardNo;

	
	private String encryptedAccount;

	
	private String longitude;
	
	private String latitude;

	public EasyHealthUser() {
		super();
	}

	public EasyHealthUser(String account, String name, String mobile, Integer cardType, String cardNo, String birthDay, Integer sex, String address,
			String passWord, String loginNonce, String deviceNumber, Long registerTime, Long lastLoginTime, String longitude, String latitude) {
		super();
		this.account = account;
		this.name = name;
		this.mobile = mobile;
		this.cardType = cardType;
		this.cardNo = cardNo;
		this.birthDay = birthDay;
		this.sex = sex;
		this.address = address;
		this.passWord = passWord;
		this.loginNonce = loginNonce;
		this.deviceNumber = deviceNumber;
		this.registerTime = registerTime;
		this.lastLoginTime = lastLoginTime;
		this.longitude = longitude;
		this.latitude = latitude;
	}

	public String getLongitude() {
		return longitude;
	}

	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}

	public String getLatitude() {
		return latitude;
	}

	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public Integer getCardType() {
		return cardType;
	}

	public void setCardType(Integer cardType) {
		this.cardType = cardType;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getAlipayId() {
		return alipayId;
	}

	public void setAlipayId(String alipayId) {
		this.alipayId = alipayId;
	}

	public String getWechatId() {
		return wecahtId;
	}

	public void setWechatId(String wechatId) {
		this.wecahtId = wechatId;
	}

	public String getPassWord() {
		return passWord;
	}

	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}

	public String getLoginNonce() {
		return loginNonce;
	}

	public void setLoginNonce(String loginNonce) {
		this.loginNonce = loginNonce;
	}

	public String getDeviceNumber() {
		return deviceNumber;
	}

	public void setDeviceNumber(String deviceNumber) {
		this.deviceNumber = deviceNumber;
	}

	public Long getRegisterTime() {
		return registerTime;
	}

	public void setRegisterTime(Long registerTime) {
		this.registerTime = registerTime;
	}

	public Long getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(Long lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	public String getHashTableName() {
		return hashTableName;
	}

	public void setHashTableName(String hashTableName) {
		this.hashTableName = hashTableName;
	}

	public String getUserId() {
		return id;
	}

	public String getBirthDay() {
		if (StringUtils.isBlank(birthDay)) {
			if (this.cardType != null && this.cardType == 1 && cardNo != null) {
				if (this.cardNo.length() == 15 || this.cardNo.length() == 18) {
					//this.birthDay = IdCardUtils.getBirthByIdCard(cardNo);
					this.birthDay = MedicalCardUtil.getBirth(this.cardNo);
				}
			}
		}/* else {
			   this.birthDay = birthDay.replaceAll("-", "");
			}*/
		return birthDay;
	}

	public void setBirthDay(String birthDay) {
		this.birthDay = birthDay;
	}

	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}

	public String getEncryptedName() {
		encryptedName = "";
		if (StringUtils.isNotEmpty(name)) {
			encryptedName = name.replaceFirst("[\u4E00-\u9FA5]", BizConstant.VIEW_SENSITIVE_CHAR);
		}
		return encryptedName;
	}

	public String getEncryptedMobile() {
		encryptedMobile = "";
		if (this.mobile != null && mobile.length() == 11) {
			encryptedMobile =
					mobile.substring(0, 3) + StringUtils.repeat(BizConstant.VIEW_SENSITIVE_CHAR, mobile.length() - 7)
							+ mobile.substring(mobile.length() - 4);
		}
		return encryptedMobile;
	}

	public String getEncryptedCardNo() {
		encryptedCardNo = "";
		if (this.cardNo != null && this.cardNo.length() > 4) {
			encryptedCardNo =
					cardNo.substring(0, 1) + StringUtils.repeat(BizConstant.VIEW_SENSITIVE_CHAR, cardNo.length() - 4)
							+ cardNo.substring(cardNo.length() - 3);
		}
		return encryptedCardNo;
	}

	public String getEncryptedAccount() {
		encryptedAccount = "";

		if (account.matches("^\\d{15}|\\d{18}|\\d{17}(x|X)$")) {
			encryptedAccount = getEncryptedCardNo();
		} else if (account.matches("^\\d{11}$")) {
			encryptedAccount = getEncryptedMobile();
		} else {
			encryptedAccount = getEncryptedCardNo();
		}

		return encryptedAccount;
	}

	@Override
	public MessagePushParamsVo convertMessagePushParams() {
		// TODO Auto-generated method stub
		return null;
	}

}
